import { defineStore } from 'pinia'
import { IS_LOCKSCREEN } from '@/constants/mutation-types'
import { storage } from '@/utils/Storage'
import { store } from '@/stores'
// 长时间不操作默认锁屏时间 半小时
const initTime = 0.5 * 60 * 60

const isLock = storage.get(IS_LOCKSCREEN, false)

export type ILockscreenState = {
  isLock: boolean // 是否锁屏
  lockTime: number
}

export const useLockScreenStore = defineStore('lockScreen', {
  state: (): ILockscreenState => ({
    isLock: isLock === true, // 是否锁屏
    lockTime: isLock == 'true' ? initTime : 0
  }),
  getters: {},
  actions: {
    setLock(payload: any) {
      this.isLock = payload
      storage.set(IS_LOCKSCREEN, this.isLock)
    },
    setLockTime(payload = initTime) {
      this.lockTime = payload
    }
  }
})
export function useLockScreenStoreOut() {
  return useLockScreenStore(store)
}
